package com.voja.workoutrandomizer;

import android.os.AsyncTask;

public class LoadDataTask extends AsyncTask<Void, Void, Void> {

	public static LoadDataTask getInstance(Main activity) {
		return new LoadDataTask(activity);
	}
	
	Main activity;
	public LoadDataTask(Main activity) {
		this.activity = activity;
	}
	
	@Override
	protected Void doInBackground(Void... params) {
		try {
			activity.workouts = new com.voja.workoutrandomizer.repository.Workouts(activity);
			activity.workouts.randomize();
			
		} catch (Exception e) {
			activity.error(e.getClass().getSimpleName() + ":\n\n" + e.getMessage());
			e.printStackTrace();
		}
		
		return null;
	}
	
	@Override
	protected void onPreExecute() {
		activity.throbberShow();
	}
	
	@Override
	protected void onPostExecute(Void result) {
		activity.throbberHide();
		activity.dataLoaded();
	}

}
